<!DOCTYPE html>
<html lang="en">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
	String basePathCl = request.getScheme()+"://"+request.getServerName()+path+"/";
%>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title></title>
<script src="<%=basePath%>weixin/js/mui.min.js"></script>
<script src="<%=basePath%>weixin/js/jquery.min.js"></script>
<%--<link rel="stylesheet" href="<%=basePath%>weixin/css/mui.min.css" />--%>

<link rel="stylesheet" href="<%=basePath%>weixin/css/base.css" />
<link rel="stylesheet" href="<%=basePath%>weixin/css/style.css" />

<script src="<%=basePath%>weixin/js/jquery.qrcode.min.js"></script>
<script src="<%=basePath%>weixin/js/page/common.js"></script>
<!-- 微信分享 -->
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script src="<%=basePath%>weixin/js/page/share.js"></script>
<script src="<%=basePath%>weixin/js/jquery.sha1.js"></script>
</head>
<body class="promotion">
<div class="promotionBox">
	<img src="<%=basePath%>weixin/img/bg-3.png" />
	<div class="ewm" id="code">
		<img src="" />
	</div>
</div>
<div class="promotionText">
	<h3>${promotionCode}</h3>
	<h3>长按复制，码上开抢</h3>
	<a id="chooseWXPay">点击付款</a>
</div>
<script>
	var data1 = {
		appid : 'wxe5b8956aa9f1485e',
		mch_id : 1388737702,
		device_info : 'WEB',
		sign : '0B422A99FE0D5668A951464BBF477C19'
	};

	(function(mui){
		mui.init();
		$("#code").qrcode({
			render: "canvas",
			text: "<%=basePath%>api/wx/store/league?promotionCode=${promotionCode}"
		});
		var _canvas = $("#code canvas")[0];
		var _img = $("#code img")[0];
		var src = _canvas.toDataURL();
		_img.src = src;
		var wxShare = {
			id : 'wxe5b8956aa9f1485e',
			ticket : '${ticket}',
			title: '开摩邦车联网',
			desc : '推广二维码 - 维修店入驻',
			imgUrl : '<%=basePathCl%>/weixin/img/bg-3.png',
			link : '<%=basePath%>api/wx/share/promotion?promotionCode=${promotionCode}'
		};
		wxShareInit(wxShare);

		document.querySelector('#chooseWXPay').onclick = function () {
			alert("chooseWXPay_onclick");
			var getPrepayId = function(){
					var timestamp = (new Date().getTime() / 1000).toFixed(0);
					data1.nonce_str = timestamp;
					$.ajax({
						type: "POST",
						url: "https://api.mch.weixin.qq.com/pay/unifiedorder",
						data: data1,
						dataType:'json',
						cache: false,
						async:false,
						success: function (data) {
							alert(data);
							init(data.prepay_id);
						}, error: function(XMLHttpRequest, textStatus, errorThrown) {
							alert(XMLHttpRequest.status+" | "+XMLHttpRequest.readyState+"|"+textStatus);
						}
					});
			};
			var init = function(prepay_id){
				wx.chooseWXPay({
					timestamp: 1414723227,
					nonceStr: 'noncestr',
					package: 'prepay_id=' + prepay_id,
					signType: 'SHA1', // 注意：新版支付接口使用 MD5 加密
					paySign: 'bd5b1933cda6e9548862944836a9b52e8c9a2b69'
				});
			};
			getPrepayId();
		};

	})(mui);
</script>
</body>

</html>
